<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <script type="text/javascript">
    let Stack2 = (()=> {
    let items = new WeakMap();

    class Stack {
      constructor() {
        items.set(this, []);
      }

      push(element) {
        let s = items.get(this);
        s.push(element);
      }

      pop(){
        let s = items.get(this);
        let r = s.pop();
        return r;
      }

      peek(){
        let s = items.get(this);
        return s[s.length-1];
      }

      isEmpty(){
        let s = items.get(this);
        return s.length === 0;
      }

      size(){
        let s = items.get(this);
        return s.length;
      }

      clear(){
        items.set(this, []);
      }

      print() {
        let s = items.get(this);
        console.log(s.toString())
      }
    }

    return Stack;
  })();
  let Queue = (()=> {
    let items = new WeakMap();

    class Queue {
      constructor() {
        items.set(this, []);
      }

      enqueue(element) {
        let s = items.get(this);
        s.push(element);
      }

      dequeue() {
        let s = items.get(this);
        let r = s.shift();
        return r;
      }

      front() {
        let s = items.get(this);
        return s[0];
      }

      isEmpty() {
        let s = items.get(this);
        return s.length === 0;
      }

      clear() {
        items.set(this, []);
      }

      size() {
        let s = items.get(this);
        return s.length;
      }

      print() {
        let s = items.get(this);
        console.log(s.toString())
      }
    }

    return Queue;
  })();

  let queue = new Queue();
  queue.enqueue('我')
  queue.enqueue('是')
  queue.enqueue('一')
  queue.enqueue('个')
  queue.enqueue('快')
  queue.enqueue('乐')
  queue.enqueue('的')
  queue.enqueue('打')
  queue.enqueue('印')
  queue.enqueue('机')
  queue.enqueue('，')
  queue.enqueue('给')
  queue.enqueue('我')
  queue.enqueue('一')
  queue.enqueue('支')
  queue.enqueue('烟')
  queue.enqueue('和')
  queue.enqueue('打')
  queue.enqueue('火')
  queue.enqueue('机')
  queue.enqueue('--华丽的分割线--')

  function start() {
    setTimeout(() => {
      const i = queue.dequeue();
      console.log(i)
      queue.enqueue(i)
      start();
    }, 1000)
  }
  start();
  // queue.enqueue(queue.dequeue())

  // var test = new Stack2();
  // test.push(queue.dequeue());
  // queue.print()
  </script>
</body>
</html>